package org.zhuxian.cn.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.zhuxian.cn.entity.Equipment;
import org.zhuxian.cn.result.JsonResult;
import org.zhuxian.cn.service.EquipmentService;

import java.util.List;

@Slf4j
@RestControllerAdvice
@RequestMapping("/equipment")
@Api(tags = "装备管理", description = "装备基础信息相关接口")
public class EquipmentController {

    @Autowired
    private EquipmentService equipmentServer;

    @ApiOperation(value = "添加装备", notes = "添加新的装备信息到系统")
    @PostMapping("add")
    public JsonResult addEquipment(@ApiParam(value = "装备信息") @RequestBody Equipment equipment) {
        equipmentServer.addEquipment(equipment);
        return new JsonResult(200, "OK");
    }

    @ApiOperation(value = "修改装备", notes = "更新已存在的装备信息")
    @PostMapping("update")
    public JsonResult modifyEquipment(@ApiParam(value = "装备信息") @RequestBody Equipment equipment) {
        equipmentServer.modifyEquipment(equipment);
        return new JsonResult(200, "OK");
    }

    @ApiOperation(value = "删除装备", notes = "根据装备ID删除装备信息")
    @DeleteMapping("/{id}")
    public JsonResult deleteEquipment(@ApiParam(value = "装备ID") @PathVariable int id) {
        equipmentServer.deleteEquipment(id);
        return new JsonResult(200, "OK");
    }

    @ApiOperation(value = "获取装备详情", notes = "根据装备ID获取装备详细信息")
    @GetMapping("/{id}")
    public JsonResult getEquipmentById(@ApiParam(value = "装备ID") @PathVariable int id) {
        Equipment equipment = equipmentServer.getEquipmentById(id);
        return new JsonResult(200, "OK", equipment);
    }

    @ApiOperation(value = "获取所有装备", notes = "获取系统中所有装备信息")
    @GetMapping("all")
    public JsonResult getAllEquipment() {
        List<Equipment> equipments = equipmentServer.getAllEquipment();
        return new JsonResult(200, "OK", equipments);
    }

    @ApiOperation(value = "按职业和部位筛选装备", notes = "根据职业名称和装备部位获取符合条件的装备信息")
    @GetMapping("/filter/{className}/{slot}")
    public JsonResult getEquipmentByClassAndSlot(
        @ApiParam(value = "职业名称") @PathVariable String className,
        @ApiParam(value = "装备部位") @PathVariable String slot) {
        List<Equipment> equipments = equipmentServer.getEquipmentByClassAndSlot(className, slot);
        return new JsonResult(200, "OK", equipments);
    }

    @ApiOperation(value = "按职业筛选装备", notes = "根据职业名称获取该职业可用的所有装备信息")
    @GetMapping("/filter/{className}")
    public JsonResult getEquipmentByClass(@ApiParam(value = "职业名称") @PathVariable String className) {
        List<Equipment> equipments = equipmentServer.getEquipmentByClass(className);
        return new JsonResult(200, "OK", equipments);
    }

    @ApiOperation(value = "获取通用装备", notes = "获取所有职业通用的装备信息")
    @GetMapping("/filter/general")
    public JsonResult getEquipmentByGeneral() {
        List<Equipment> equipments = equipmentServer.getEquipmentByGeneral();
        return new JsonResult(200, "OK", equipments);
    }
}